import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// import Icons from 'unplugin-icons/vite'
// import IconsResolver from 'unplugin-icons/resolver'

import { resolve } from 'path'
// @ts-ignore
import config from './src/config/index'


// https://vitejs.dev/config/
export default defineConfig({
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        additionalData: `@import "${resolve(__dirname, 'src/styles/index.less')}";`
      }
    }
  },
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue'],
      resolvers: [
        ElementPlusResolver(),
        // IconsResolver({
        //   componentPrefix: 'Icon',
        //   enabledCollections: ["ep"]
        // })
      ],
      dts: './auto-imports.d.ts'
    }),
    Components({
      resolvers: [
        ElementPlusResolver(),
        // IconsResolver({
        //   prefix: 'Icon',
        //   enabledCollections: ['ep'],
        // }),
      ],
      dts: './components.d.ts'
    }),
    // Icons({
    //   autoInstall: true,
    //   compiler: 'vue3'
    // }),
  ],
  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, 'src')
      },
      {
        find: 'comps',
        replacement: resolve(__dirname, 'src/components')
      }
    ]
  },
  server: {
    proxy: {
      '/api': {
        target: config.baseUrl,
        changeOrigin: true
      }
    },
    port: 5174,
    open: true
  }
})
